<template>
  <div class="page-container">
    <el-card class="content-container">
      <div class="toolbar">
        <div class="toolbar-left">
          <h3>产品分类管理</h3>
        </div>
        <div class="toolbar-right">
          <el-button type="primary" @click="handleAdd">
            <el-icon><Plus /></el-icon>
            新增分类
          </el-button>
        </div>
      </div>

      <!-- 数据表格 -->
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="dicCode" label="分类编码" />
        <el-table-column prop="dicName" label="分类名称" />
        <el-table-column prop="codeIndex" label="排序" width="100" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button type="primary" size="small" @click="handleEdit(scope.row)">
              编辑
            </el-button>
            <el-button type="danger" size="small" @click="handleDelete(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'

// 响应式数据
const loading = ref(false)
const tableData = ref([])

// 模拟数据
const mockData = [
  {
    id: 1,
    dicCode: 'vegetables',
    dicName: '蔬菜',
    codeIndex: 1,
    createTime: '2024-08-16 10:30:00'
  },
  {
    id: 2,
    dicCode: 'fruits',
    dicName: '水果',
    codeIndex: 2,
    createTime: '2024-08-16 10:31:00'
  },
  {
    id: 3,
    dicCode: 'grains',
    dicName: '粮食',
    codeIndex: 3,
    createTime: '2024-08-16 10:32:00'
  }
]

// 方法
const loadData = () => {
  loading.value = true
  
  // 模拟API调用
  setTimeout(() => {
    tableData.value = mockData
    loading.value = false
  }, 500)
}

const handleAdd = () => {
  ElMessage.info('新增分类功能开发中...')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑分类: ${row.dicName}`)
}

const handleDelete = (row) => {
  ElMessageBox.confirm(
    `确定要删除分类"${row.dicName}"吗？`,
    '确认删除',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }
  ).then(() => {
    ElMessage.success('删除成功')
    loadData()
  })
}

// 生命周期
onMounted(() => {
  loadData()
})
</script>

<style lang="scss" scoped>
@import '@/styles/index.scss';
</style>
